#include <cstdint>
#include <iostream>
#include <istream>
#include <iterator>
#include <set>
using ll = int64_t;

const ll maxn = 2e5+5;
ll n,a[maxn],idx[maxn],ls[maxn],rs[maxn];
std::set<ll> s;

int main(){
    std::iostream::sync_with_stdio(false);
    std::cin.tie(nullptr);

    std::cin>>n;
    for(ll i=1;i<=n;i++){
        std::cin>>a[i];
        idx[a[i]]=i;
    }
    s.insert(a[1]);
    for(ll i=2;i<=n;i++){
        auto p = s.upper_bound(a[i]);
        ll u = 0;
        if(p!=s.end()){
            u=*p;
        }
        if(p!=s.begin() && (!u || idx[u]<idx[*std::prev(p)])){
            u=*std::prev(p);
        }
        if(a[i]>u){ //比父亲大
            rs[u]=a[i];
        }else{
            ls[u]=a[i];
        }
        s.insert(a[i]);
    }
    //TODO
}